package org.example.netty.heartbeat;

import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.timeout.IdleStateEvent;
import io.netty.handler.timeout.IdleStateHandler;
import io.netty.handler.timeout.ReadTimeoutHandler;

import java.util.concurrent.TimeUnit;

/**
 * @see ReadTimeoutHandler
 */
public class HeartbeatServerHandler2 extends IdleStateHandler {
    public static final int READ_IDLE_GAP = 150;

    public HeartbeatServerHandler2() {
        super(READ_IDLE_GAP, 0, 0, TimeUnit.SECONDS);
    }

    @Override
    protected void channelIdle(ChannelHandlerContext ctx, IdleStateEvent evt) throws Exception {
        super.channelIdle(ctx, evt);
        System.out.println(READ_IDLE_GAP + "秒内关闭数据，关闭连接");
    }

    @Override
    public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
        if(null==msg||msg instanceof Object){
            super.channelRead(ctx,msg);
            return;
        }
        super.channelRead(ctx, msg);
    }
}
